//
//  MyAssetsView.m
//  PYWGetColor
//
//  Created by 杜文杰 on 2018/6/15.
//  Copyright © 2018年 dwj. All rights reserved.
//

#import "MyAssetsView.h"

@interface MyAssetsView()
@property(nonatomic,strong) UIView *bgView;
@property(nonatomic,strong) UILabel *makesureMoneyLb;
@property(nonatomic,strong) UIImageView *moneyImgView;
@property(nonatomic,strong) UIButton *makesureMoneyBtn; // 确认金额按钮
@end

@implementation MyAssetsView
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.alpha = 0;
        UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        backButton.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75];
        [backButton addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:backButton];
        [self addSubview:self.bgView];
        
        [self.bgView addSubview:self.makesureMoneyLb];
        [self.bgView addSubview:self.moneyImgView];
        [self.bgView addSubview:self.moneyField];
        
        __weak __typeof(self)weakSelf = self;
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf.mas_centerY);
            make.centerX.equalTo(weakSelf.mas_centerX);
            make.height.mas_equalTo(203 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(330 / WIDTH_6S_SCALE);
        }];
        [self.makesureMoneyLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.bgView.mas_top).offset(20 / HEIGHT_6S_SCALE);
            make.left.equalTo(weakSelf.bgView.mas_left).offset(20 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(100 / WIDTH_6S_SCALE);
        }];
        [self.moneyImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.makesureMoneyLb.mas_left);
            make.top.equalTo(weakSelf.makesureMoneyLb.mas_bottom).offset(30 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(15 / WIDTH_6S_SCALE);
        }];
        [self.moneyField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.moneyImgView.mas_right).offset(15 / WIDTH_6S_SCALE);
            make.right.equalTo(weakSelf.mas_right).offset(-5 / WIDTH_6S_SCALE);
            make.centerY.equalTo(weakSelf.moneyImgView.mas_centerY);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        UIView *lineView = [[UIView alloc]init];
        lineView.backgroundColor = getColor(dividerColor);
        [self.bgView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf);
            make.height.mas_equalTo(1);
            make.top.equalTo(weakSelf.moneyField.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
        }];
        [self.bgView addSubview:self.makesureMoneyBtn];
        [self.makesureMoneyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.bgView.mas_left).offset(48 / WIDTH_6S_SCALE);
            make.right.equalTo(weakSelf.bgView.mas_right).offset(-48 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(45 / HEIGHT_6S_SCALE);
            make.bottom.equalTo(weakSelf.bgView.mas_bottom).offset(-30 / HEIGHT_6S_SCALE);
        }];
    }
    return self;
}

#pragma mark -- init

- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = getColor(whiteColor);
        _bgView.layer.cornerRadius = 5;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}
#pragma mark -- show hidden

//出现
- (void)show{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}

//消失
- (void)hidden{
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0 ;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (UILabel *)makesureMoneyLb
{
    if (!_makesureMoneyLb) {
        _makesureMoneyLb = [[UILabel alloc]init];
        _makesureMoneyLb.backgroundColor = [UIColor clearColor];
        _makesureMoneyLb.textColor = getColor(textColor);
        _makesureMoneyLb.textAlignment = NSTextAlignmentLeft;
        _makesureMoneyLb.font = DEF_FontSize_14;
        _makesureMoneyLb.text = @"确认金额";
    }
    return _makesureMoneyLb;
}
- (UIImageView *)moneyImgView
{
    if (!_moneyImgView) {
        _moneyImgView = [[UIImageView alloc]init];
        _moneyImgView.backgroundColor = [UIColor clearColor];
        _moneyImgView.userInteractionEnabled = YES;
        _moneyImgView.image = [UIImage imageNamed:@"rmb"];
    }
    return _moneyImgView;
}
- (UITextField *)moneyField
{
    if (!_moneyField) {
        _moneyField = [[UITextField alloc]init];
        _moneyField.backgroundColor = [UIColor clearColor];
        _moneyField.textColor = getColor(blackColor);
        _moneyField.font = DEF_FontSize_18;
        _moneyField.textAlignment = NSTextAlignmentLeft;
        _moneyField.keyboardType = UIKeyboardTypeDecimalPad;
//        _moneyField.text = @"270";
    }
    return _moneyField;
}
- (UIButton *)makesureMoneyBtn
{
    if (!_makesureMoneyBtn) {
        _makesureMoneyBtn = [[UIButton alloc]init];
        _makesureMoneyBtn.backgroundColor = getColor(mainColor);
        [_makesureMoneyBtn setTitleColor:getColor(whiteColor) forState:UIControlStateNormal];
        [_makesureMoneyBtn setTitle:@"确认提现" forState:UIControlStateNormal];
        _makesureMoneyBtn.layer.cornerRadius = 5;
        _makesureMoneyBtn.layer.masksToBounds = YES;
        [_makesureMoneyBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _makesureMoneyBtn;
}
- (void)btnAction:(UIButton *)btn
{
    NSLog(@"确认提现");
    if (self.txBtnBlock) {
        self.txBtnBlock(self.moneyField.text);
    }
}
@end


